package com.scud.model.product.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProductSpec {
    //主键id
    private Long id;
    //规格名称
    private String name;
    //规格详情
    private String value;
    //所属商品id，逻辑外键
    private Long productId;
    //创建时间
    private LocalDateTime createTime;

    public List<String> listOfValue() {
        if (Objects.isNull(this.value)) {
            return null;
        }
        int length = this.value.length();
        if (length == 0) {
            return null;
        }
        String str = value.substring(1, length - 1);
        String[] split = str.split(",");
        for (int i = 0; i < split.length; i++) {
            String replace = split[i].replace(" ", "");
            split[i]=replace;
        }
        return new ArrayList<>(List.of(split));
    }
}
